package com.laikan.reader.core.utils;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import cn.sharesdk.framework.Platform;
import com.laikan.library.httpvolley.engine.HttpApiRequestEngine;
import com.laikan.library.httpvolley.engine.Requester;
import com.laikan.library.httpvolley.helper.RequestListener;
import com.laikan.library.httpvolley.helper.VolleyErrorHandler;
import com.laikan.library.httpvolley.response.HttpResponse;
import com.laikan.library.utils.SPUtil;
import com.laikan.reader.comment.APIProtocol;
import com.socks.library.KLog;

import java.util.HashMap;

/**
 * @author wx
 * @version 创建时间：2016-1-21 下午5:22:51
 * @E-mail wx1343571153@163.com
 * @category 分享统计
 */

public class UIHeadler extends Handler {

    private Context context;
    private String shareType;
    private String shareId;
    private String bookId;

    public UIHeadler(Context context, String bookId, String shareId) {
        this.shareId = shareId;
        this.context = context;
        this.bookId = bookId;
    }

    /*
     * (non-Javadoc)
     *
     * @see android.os.Handler#handleMessage(android.os.Message)
     */
    @Override
    public void handleMessage(Message msg) {

        super.handleMessage(msg);
        Platform pl = (Platform)msg.obj;
        formName(pl.getName());

        HashMap<String, String> map = new HashMap<String, String>();
        map.put("sd", SPUtil.getString("token", ""));
        map.put("shareType", shareType);
        map.put("shareId", shareId);
        RequestListener requestListener = new RequestListener() {
            @Override
            public void onPreExecute() { KLog.e("---------volley onPreExecute!!!"); }

            @Override
            public void onSuccess(HttpResponse httpResponse) {
                System.out.println(httpResponse.responseContent);
            }

            @Override
            public void onError(VolleyErrorHandler errorHandler) {

            }

            @Override
            public void onFinish() {

            }
        };

        Requester requester = new Requester();
        requester.setUrl(APIProtocol.laikan_get_updata_sharebook);
        requester.setMapBody(map);
        HttpApiRequestEngine.getInstance().httpPostRequest(requester, requestListener);

//        HttpApiRequestEngine.getInstance().httpPostRequest(APIProtocol.laikan_get_updata_sharebook, map, null, null, requestListener);
    }

    public void formName(String name) {

        if (name.equals("QQ")) {
            shareType = "3";
        }else if (name.equals("WechatMoments")) {
            shareType = "2";
        }else if (name.equals("SinaWeibo")) {
            shareType = "5";
        }else if (name.equals("Wechat")) {
            shareType = "0";
        }else if (name.equals("QZone")) {
            shareType = "4";
        }else if (name.equals("WechatFavorite")) {
            shareType = "1";
        }
    }

}
